Convert Miles to Kilometers

Theory:

1 mile is equal to 1.60934 kilometers.

Python Code:

def miles_to_kilometers(miles):
    return miles * 1.60934

# Taking input for miles and converting them to kilometers
def convert_and_display_miles_to_kilometers():
    miles = float(input("Enter the distance in miles: "))
    kilometers = miles_to_kilometers(miles)
    print("Distance in kilometers:", kilometers)

convert_and_display_miles_to_kilometers()

Example Output 1:

Enter the distance in miles: 10

Distance in kilometers: 16.0934

Example Output 2:

Enter the distance in miles: 25

Distance in kilometers: 40.2335

Code Explanation:

The function miles_to_kilometers(miles) converts miles to kilometers using the conversion factor.

The function convert_and_display_miles_to_kilometers() takes input for miles, converts them to kilometers using the aforementioned function, and displays the result.